package com.zhoug.common.utils;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.widget.NumberPicker;

import java.lang.reflect.Field;

/**
 * NumberPicker 工具
 *
 * @Author 35574
 * @Date 2020/12/15
 * @Description
 */
public class NumberPickerUtils {
    /**
     * 设置NumberPicker 分割线颜色
     * 在NumberPicker 的 setDisplayedValues后调用
     *
     * @param numberPicker
     */
    public static void setNumberPickerDividerColor(NumberPicker numberPicker, int color) {
        if(numberPicker==null)return;
        final NumberPicker picker = numberPicker;
        Field[] pickerFields = NumberPicker.class.getDeclaredFields();
        for (Field pf : pickerFields) {
            if (pf.getName().equals("mSelectionDivider")) {
                pf.setAccessible(true);
                try {
                    //设置分割线的颜色值
                    pf.set(picker, new ColorDrawable(color));
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            }
        }
    }
}
